package net.csdn.business.notify.api.service.impl;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.notify.api.service.ISendMqService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;


/**
 * @ClassName MqSendMqServiceImpl
 * @Description TODO
 * @Author zhangyl
 * @Date 2023/11/30 11:44
 */
@Slf4j
@Service
public class MqSendMqServiceImpl implements ISendMqService {

    @Autowired
    private ProducerBean aliProducer;


    @Override
    public void send(String topic, String content, String tag) {
        try {
            Message message = new Message(topic, tag, content.getBytes(StandardCharsets.UTF_8));
            SendResult result = aliProducer.send(message);
            log.info("==== notify tcp send MQ message success,topic={},tag={},content={},msgId={}", topic, tag, content, result.getMessageId());
        }catch (Exception e){
            log.info("==== notify tcp send MQ message faild,please check mq config!!!!");
        }
    }

    @Override
    public void send(String topic, String content) {
        try {
            Message message = new Message(topic, null, content.getBytes(StandardCharsets.UTF_8));
            SendResult result = aliProducer.send(message);
            log.info("==== notify tcp send MQ message success,topic={},content={},msgId={}", topic, content, result.getMessageId());
        }catch (Exception e){
            log.info("==== notify tcp send MQ message faild,please check mq config!!!!");
        }
    }
}
